/*
 * thread_pool.h
 *
 *  Created on: 2008-12-29
 *      Author: fanliangliang
 */

#ifndef TEST_THREAD_POOL_H_
#define TEST_THREAD_POOL_H_

#include "toxic.h"
#include <iostream>

using namespace toxic;

static void print(int i) {
	Thread::sleep(10);
	xdebug << Thread::self() << ":" << i;
}

static void add_task(ThreadPool* pool, int begin) {
	for (int i = begin, end = begin + 300; i < end; ++i) {
		pool->schedule(bind(&print, i));
		Thread::sleep(10);
	}
}

void do_test_thread_pool() {

	cout << "***** thread_pool *****" << endl;

	xlog.setLevel(LEVEL_TRACE);
	xlog.addAppender(cout);
	//xlog.addAppender("E:/tp.log");

	ThreadPool pool(5);

	Thread t1(bind(&add_task, &pool, 0));
	Thread t2(bind(&add_task, &pool, 300));
	Thread t3(bind(&add_task, &pool, 600));

	t1.start();
	t2.start();
	t3.start();
	t1.join();
	t2.join();
	t3.join();

	pool.wait();

}

#endif /* TEST_THREAD_POOL_H_ */
